<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Validate;

/**
 * 申请博主接口
 */
class Bloggerapply extends Api
{
    protected $noNeedRight = ['*'];

    //申请
    public function apply()
    {
        $data = [
            'user_id'=>$this->auth->id,
            'platform'=>input('platform','dy'),
            'province'=>input('province',0),
            'province_name'=>input('province_name',''),
            'city'=>input('city',0),
            'city_name'=>input('city_name',''),
            'area'=>input('area',0),
            'area_name'=>input('area_name',''),
            'account_id'=>input('account_id',''),
            'fans_num'=>input('fans_num',0),
            'mobile'=>input('mobile',''),
            'wechat'=>input('wechat',''),
        ];

        if (empty($data['account_id'])){
            $this->error('请输入平台账号id');
        }
        if (empty($data['fans_num'])){
            $this->error('请输入粉丝数');
        }
        if (empty($data['mobile'])){
            $this->error('请输入联系电话');
        }
        if (empty($data['wechat'])){
            $this->error('请输入微信号');
        }
        if ($data['mobile'] && !Validate::regex($data['mobile'], "^1\d{10}$")) {
            $this->error('联系电话格式错误');
        }
        $data['full_address'] = $data['province_name'].$data['city_name'].$data['area_name'];
        $apply_model = new \app\admin\model\blogger\BloggerApply();

        $res = $apply_model->save($data);

        $this->success('请求成功',$res);
    }
}